//
//Form made by DAVID LADNIER
//

#pragma once

//CTRL + A + K + F is auto-format shortcut

#include <string>  
#include <iostream>  
#include <fstream> 
#include <istream>
#include <sstream>
#include "Class.h"
#include "LinkedConflict.h"

using namespace std;

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace ClassNamespace;

int first = 1;
int second= -1;


namespace Project3 {

	/// <summary>
	/// Summary for UIForm
	/// </summary>
	public ref class UIForm : public System::Windows::Forms::Form
	{
	public:
		UIForm(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~UIForm()
		{
			if (components)
			{
				delete components;
			}
		}

	private: System::Windows::Forms::OpenFileDialog^  openFileDialog;
	private: System::Windows::Forms::Button^  FileButton;
	private: System::Windows::Forms::ComboBox^  departmentName;
	private: System::Windows::Forms::ComboBox^  courseNumber;
	private: System::Windows::Forms::ComboBox^  sectionNumber;
	private: System::Windows::Forms::ComboBox^  startTime;
	private: System::Windows::Forms::ComboBox^  endTime;
	private: System::Windows::Forms::ComboBox^  buildingName;
	private: System::Windows::Forms::ComboBox^  roomNumber;
	private: System::Windows::Forms::ComboBox^  instructorName;
	private: System::Windows::Forms::Label^  departmentLabel;
	private: System::Windows::Forms::Label^  courseLabel;
	private: System::Windows::Forms::Label^  sectionLabel;
	private: System::Windows::Forms::Label^  startLabel;
	private: System::Windows::Forms::Label^  endLabel;
	private: System::Windows::Forms::Label^  buildingLabel;
	private: System::Windows::Forms::Label^  roomLabel;
	private: System::Windows::Forms::Label^  instructorLabel;
	private: System::Windows::Forms::ListBox^ listBox1;
	private: System::Windows::Forms::RichTextBox^  richTextBox;
	private: System::Windows::Forms::Button^  addClassButt; //LOL //LMAO

			 //The check boxes/labels for setting a class as dual-taught or crosslisted
			 //NW
	private: System::Windows::Forms::Label^  classListLabel;
	private: System::Windows::Forms::Label^  crossBoxLabel;
	private: System::Windows::Forms::Label^  dualBoxLabel;
	private: System::Windows::Forms::CheckBox^ crossBox;
	private: System::Windows::Forms::CheckBox^ dualBox;
	private: System::Windows::Forms::ListBox^ classBox;
	private: System::Windows::Forms::Label^ modsLabel;


	private: String^ openFileName;
	private: bool fileOpened;
	private: String^ directoryPath;
	private: System::Windows::Forms::ComboBox^  daysOfWeek;
	private: System::Windows::Forms::Label^  daysLabel;

			 //some variables used for storing the classes etc
			 //NW
	private: array<Class*> ^classArray;
	public: /*int first = 1;
			int second = -1;*/
			array<int> ^selectedItems;



	protected:

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			//initializing the class array
			classArray = gcnew array<Class*>(1000);
			selectedItems = gcnew array<int>(4);
			//end class array initializing
			this->openFileDialog = (gcnew System::Windows::Forms::OpenFileDialog());
			this->FileButton = (gcnew System::Windows::Forms::Button());
			this->departmentName = (gcnew System::Windows::Forms::ComboBox());
			this->courseNumber = (gcnew System::Windows::Forms::ComboBox());
			this->sectionNumber = (gcnew System::Windows::Forms::ComboBox());
			this->startTime = (gcnew System::Windows::Forms::ComboBox());
			this->endTime = (gcnew System::Windows::Forms::ComboBox());
			this->buildingName = (gcnew System::Windows::Forms::ComboBox());
			this->roomNumber = (gcnew System::Windows::Forms::ComboBox());
			this->instructorName = (gcnew System::Windows::Forms::ComboBox());
			this->departmentLabel = (gcnew System::Windows::Forms::Label());
			this->courseLabel = (gcnew System::Windows::Forms::Label());
			this->sectionLabel = (gcnew System::Windows::Forms::Label());
			this->startLabel = (gcnew System::Windows::Forms::Label());
			this->endLabel = (gcnew System::Windows::Forms::Label());
			this->buildingLabel = (gcnew System::Windows::Forms::Label());
			this->roomLabel = (gcnew System::Windows::Forms::Label());
			this->instructorLabel = (gcnew System::Windows::Forms::Label());
			this->richTextBox = (gcnew System::Windows::Forms::RichTextBox());
			this->addClassButt = (gcnew System::Windows::Forms::Button());
			this->daysOfWeek = (gcnew System::Windows::Forms::ComboBox());
			this->daysLabel = (gcnew System::Windows::Forms::Label());

			//instantiating all of the checkbox items and the listboxes
			//NW
			this->listBox1 = (gcnew System::Windows::Forms::ListBox());
			this->classListLabel = (gcnew System::Windows::Forms::Label());
			this->dualBox = (gcnew System::Windows::Forms::CheckBox());
			this->crossBox = (gcnew System::Windows::Forms::CheckBox());
			this->dualBoxLabel = (gcnew System::Windows::Forms::Label());
			this->crossBoxLabel = (gcnew System::Windows::Forms::Label());
			this->classBox = (gcnew System::Windows::Forms::ListBox());
			this->modsLabel = (gcnew System::Windows::Forms::Label());
			this->SuspendLayout();
			// 
			// openFileDialog
			// 
			this->openFileDialog->FileName = L"openFileDialog";
			this->openFileDialog->Filter = "text files (*.txt)|*.txt";
			this->openFileDialog->FilterIndex = 3;
			// 
			// FileButton
			// 
			this->FileButton->Location = System::Drawing::Point(12, 12);
			this->FileButton->Name = L"FileButton";
			this->FileButton->Size = System::Drawing::Size(75, 23);
			this->FileButton->TabIndex = 0;
			this->FileButton->Text = L"Open File";
			this->FileButton->UseVisualStyleBackColor = true;
			this->FileButton->Click += gcnew System::EventHandler(this, &UIForm::FileButton_Click);
			// 
			// departmentName
			// 
			this->departmentName->FormattingEnabled = true;
			this->departmentName->Items->AddRange(gcnew cli::array< System::Object^  >(1) { L"CS" });
			this->departmentName->Location = System::Drawing::Point(13, 61);
			this->departmentName->Name = L"departmentName";
			this->departmentName->Size = System::Drawing::Size(80, 21);
			this->departmentName->TabIndex = 2;
			this->departmentName->Text = L"Department";
			// 
			// courseNumber
			// 
			this->courseNumber->FormattingEnabled = true;
			this->courseNumber->Items->AddRange(gcnew cli::array< System::Object^  >(23) {
				L"108", L"111", L"140", L"150", L"234", L"240",
					L"312", L"314", L"321", L"325", L"330", L"340", L"382", L"423", L"425", L"434", L"438", L"447", L"454", L"456", L"482", L"490",
					L"499"
			});
			this->courseNumber->Location = System::Drawing::Point(99, 61);
			this->courseNumber->Name = L"courseNumber";
			this->courseNumber->Size = System::Drawing::Size(70, 21);
			this->courseNumber->TabIndex = 3;
			this->courseNumber->Text = L"Course #";
			// 
			// sectionNumber
			// 
			this->sectionNumber->FormattingEnabled = true;
			this->sectionNumber->Items->AddRange(gcnew cli::array< System::Object^  >(10) {
				L"001", L"002", L"003", L"004", L"005", L"006",
					L"007", L"008", L"009", L"010"
			});
			this->sectionNumber->Location = System::Drawing::Point(175, 60);
			this->sectionNumber->Name = L"sectionNumber";
			this->sectionNumber->Size = System::Drawing::Size(72, 21);
			this->sectionNumber->TabIndex = 6;
			this->sectionNumber->Text = L"Section #";
			// 
			// startTime
			// 
			this->startTime->FormattingEnabled = true;
			this->startTime->Items->AddRange(gcnew cli::array< System::Object^  >(25) {
				L"800", L"830", L"900", L"930", L"1000", L"1030",
					L"1100", L"1130", L"1200", L"1230", L"1300", L"1330", L"1400", L"1430", L"1500", L"1530", L"1600", L"1630", L"1700", L"1730",
					L"1800", L"1830", L"1900", L"1930", L"2000"
			});
			this->startTime->Location = System::Drawing::Point(371, 60);
			this->startTime->Name = L"startTime";
			this->startTime->Size = System::Drawing::Size(74, 21);
			this->startTime->TabIndex = 7;
			this->startTime->Text = L"Start Time";
			// 
			// endTime
			// 
			this->endTime->FormattingEnabled = true;
			this->endTime->Items->AddRange(gcnew cli::array< System::Object^  >(49) {
				L"850", L"915", L"930", L"945", L"950", L"1015",
					L"1030", L"1045", L"1050", L"1115", L"1130", L"1145", L"1150", L"1215", L"1230", L"1245", L"1250", L"1315", L"1330", L"1345",
					L"1350", L"1415", L"1430", L"1445", L"1450", L"1515", L"1530", L"1545", L"1550", L"1615", L"1630", L"1645", L"1650", L"1715",
					L"1730", L"1745", L"1750", L"1815", L"1830", L"1845", L"1850", L"1915", L"1930", L"1945", L"1950", L"2015", L"2030", L"2045",
					L"2050"
			});
			this->endTime->Location = System::Drawing::Point(451, 60);
			this->endTime->Name = L"endTime";
			this->endTime->Size = System::Drawing::Size(70, 21);
			this->endTime->TabIndex = 8;
			this->endTime->Text = L"End Time";
			// 
			// buildingName
			// 
			this->buildingName->FormattingEnabled = true;
			this->buildingName->Items->AddRange(gcnew cli::array< System::Object^  >(1) { L"EB" });
			this->buildingName->Location = System::Drawing::Point(527, 60);
			this->buildingName->Name = L"buildingName";
			this->buildingName->Size = System::Drawing::Size(61, 21);
			this->buildingName->TabIndex = 9;
			this->buildingName->Text = L"Building";
			// 
			// roomNumber
			// 
			this->roomNumber->FormattingEnabled = true;
			this->roomNumber->Items->AddRange(gcnew cli::array< System::Object^  >(39) {
				L"0007", L"0010", L"0011", L"0012", L"0013", L"0014",
					L"0015", L"0028", L"0033", L"0040", L"0041", L"0044", L"0050", L"0051", L"0052", L"1008", L"1009", L"1010", L"1011", L"1012",
					L"1023", L"1026", L"1027", L"1033", L"2008", L"2009", L"2010", L"2011", L"2012", L"2013", L"2025", L"2026", L"2029", L"2030",
					L"3008", L"3009", L"3010", L"3012", L"3013"
			});
			this->roomNumber->Location = System::Drawing::Point(594, 60);
			this->roomNumber->Name = L"roomNumber";
			this->roomNumber->Size = System::Drawing::Size(65, 21);
			this->roomNumber->TabIndex = 10;
			this->roomNumber->Text = L"Room #";
			// 
			// instructorName
			// 
			this->instructorName->FormattingEnabled = true;
			this->instructorName->Items->AddRange(gcnew cli::array< System::Object^  >(11) {
				L"Bouvier", L"Crk", L"Ercal", L"Fujinoki",
					L"Klein", L"Mayer", L"McKenney", L"Tornaritis", L"Weinberg", L"White", L"Yu"
			});
			this->instructorName->Location = System::Drawing::Point(665, 60);
			this->instructorName->Name = L"instructorName";
			this->instructorName->Size = System::Drawing::Size(78, 21);
			this->instructorName->TabIndex = 11;
			this->instructorName->Text = L"Instructor";
			// 
			// departmentLabel
			// 
			this->departmentLabel->AutoSize = true;
			this->departmentLabel->Location = System::Drawing::Point(12, 45);
			this->departmentLabel->Name = L"departmentLabel";
			this->departmentLabel->Size = System::Drawing::Size(62, 13);
			this->departmentLabel->TabIndex = 12;
			this->departmentLabel->Text = L"Department";
			// 
			// courseLabel
			// 
			this->courseLabel->AutoSize = true;
			this->courseLabel->Location = System::Drawing::Point(99, 45);
			this->courseLabel->Name = L"courseLabel";
			this->courseLabel->Size = System::Drawing::Size(50, 13);
			this->courseLabel->TabIndex = 13;
			this->courseLabel->Text = L"Course #";
			// 
			// sectionLabel
			// 
			this->sectionLabel->AutoSize = true;
			this->sectionLabel->Location = System::Drawing::Point(175, 45);
			this->sectionLabel->Name = L"sectionLabel";
			this->sectionLabel->Size = System::Drawing::Size(53, 13);
			this->sectionLabel->TabIndex = 14;
			this->sectionLabel->Text = L"Section #";
			// 
			// startLabel
			// 
			this->startLabel->AutoSize = true;
			this->startLabel->Location = System::Drawing::Point(371, 45);
			this->startLabel->Name = L"startLabel";
			this->startLabel->Size = System::Drawing::Size(55, 13);
			this->startLabel->TabIndex = 15;
			this->startLabel->Text = L"Start Time";
			// 
			// endLabel
			// 
			this->endLabel->AutoSize = true;
			this->endLabel->Location = System::Drawing::Point(451, 45);
			this->endLabel->Name = L"endLabel";
			this->endLabel->Size = System::Drawing::Size(52, 13);
			this->endLabel->TabIndex = 16;
			this->endLabel->Text = L"End Time";
			// 
			// buildingLabel
			// 
			this->buildingLabel->AutoSize = true;
			this->buildingLabel->Location = System::Drawing::Point(527, 45);
			this->buildingLabel->Name = L"buildingLabel";
			this->buildingLabel->Size = System::Drawing::Size(44, 13);
			this->buildingLabel->TabIndex = 17;
			this->buildingLabel->Text = L"Building";
			// 
			// roomLabel
			// 
			this->roomLabel->AutoSize = true;
			this->roomLabel->Location = System::Drawing::Point(593, 45);
			this->roomLabel->Name = L"roomLabel";
			this->roomLabel->Size = System::Drawing::Size(45, 13);
			this->roomLabel->TabIndex = 18;
			this->roomLabel->Text = L"Room #";
			// 
			// instructorLabel
			// 
			this->instructorLabel->AutoSize = true;
			this->instructorLabel->Location = System::Drawing::Point(665, 45);
			this->instructorLabel->Name = L"instructorLabel";
			this->instructorLabel->Size = System::Drawing::Size(51, 13);
			this->instructorLabel->TabIndex = 19;
			this->instructorLabel->Text = L"Instructor";
			//
			//Dual checkbox and Cross listed checkbox
			//NW
			this->dualBox->AutoSize = true;
			this->dualBox->Location = System::Drawing::Point(900, 60);
			this->dualBox->Name = L"dualBox";
			this->dualBox->Size = System::Drawing::Size(25, 25);
			this->dualBox->TabIndex = 30;
			this->dualBox->Click += gcnew System::EventHandler(this, &UIForm::dualbox_Click);
			//Cross listed box
			this->crossBox->AutoSize = true;
			this->crossBox->Location = System::Drawing::Point(1030, 60);
			this->crossBox->Name = L"crossBox";
			this->crossBox->Size = System::Drawing::Size(25, 25);
			this->crossBox->TabIndex = 30;
			this->crossBox->Click += gcnew System::EventHandler(this, &UIForm::crossListBox_Click);
			//
			//Dual label and Cross label
			//NW
			this->dualBoxLabel->AutoSize = true;
			this->dualBoxLabel->Location = System::Drawing::Point(915, 60);
			this->dualBoxLabel->Name = L"dualBoxLabel";
			this->dualBoxLabel->Size = System::Drawing::Size(50, 30);
			this->dualBoxLabel->TabIndex = 32;
			this->dualBoxLabel->Text = L"Class is dual taught";
			//Cross Listed Label
			this->crossBoxLabel->AutoSize = true;
			this->crossBoxLabel->Location = System::Drawing::Point(1045, 60);
			this->crossBoxLabel->Name = L"crossBoxLabel";
			this->crossBoxLabel->Size = System::Drawing::Size(50, 30);
			this->crossBoxLabel->TabIndex = 31;
			this->crossBoxLabel->Text = L"Class is crosslisted";
			//
			// Class List Label
			// NW
			this->classListLabel->AutoSize = true;
			this->classListLabel->Location = System::Drawing::Point(350, 300);
			this->classListLabel->Name = L"classListLabel";
			this->classListLabel->Size = System::Drawing::Size(120, 60);
			this->classListLabel->TabIndex = 29;
			this->classListLabel->Text = L"Classes";
			this->classListLabel->Font = (gcnew System::Drawing::Font(L"Arial", 20));
			//
			//Class modifications label
			//NW
			this->modsLabel->AutoSize = true;
			this->modsLabel->Location = System::Drawing::Point(900, 20);
			this->modsLabel->Name = L"classModsLabel";
			this->modsLabel->Size = System::Drawing::Size(120, 60);
			this->modsLabel->TabIndex = 37;
			this->modsLabel->Text = L"Class Modifications";
			this->modsLabel->Font = (gcnew System::Drawing::Font(L"Arial", 20));
			// 
			// richTextBox
			// David Ladnier
			// Revised by NW
			this->richTextBox->Cursor = System::Windows::Forms::Cursors::IBeam;
			this->richTextBox->Location = System::Drawing::Point(13, 89);
			this->richTextBox->Name = L"richTextBox";
			this->richTextBox->ReadOnly = true;
			this->richTextBox->Size = System::Drawing::Size(811, 180);
			this->richTextBox->TabIndex = 20;
			this->richTextBox->Text = L"";
			//
			//Classes lsitbox
			//NW
			this->listBox1->Cursor = System::Windows::Forms::Cursors::Cross;
			this->listBox1->Location = System::Drawing::Point(13, 350);
			this->listBox1->Name = L"List box";
			this->listBox1->Size = System::Drawing::Size(811, 180);
			this->listBox1->TabIndex = 24;
			this->listBox1->Text = L"";
			this->listBox1->SelectionMode = SelectionMode::MultiSimple;
			this->listBox1->Click += gcnew System::EventHandler(this, &UIForm::listbox1_Click);
			//
			//Class dual taught and cross listed listbox
			//NW
			this->classBox->Cursor = System::Windows::Forms::Cursors::Cross;
			this->classBox->Location = System::Drawing::Point(900, 89);
			this->classBox->Name = L"Class List Box";
			this->classBox->Size = System::Drawing::Size(300, 450);
			this->classBox->TabIndex = 33;
			this->classBox->Text = L"";
			this->classBox->SelectionMode = SelectionMode::One;
			this->classBox->Click += gcnew System::EventHandler(this, &UIForm::classbox_Click);
			// 
			// addClassButt
			// 
			this->addClassButt->Location = System::Drawing::Point(749, 60);
			this->addClassButt->Name = L"addClassButt";
			this->addClassButt->Size = System::Drawing::Size(75, 23);
			this->addClassButt->TabIndex = 21;
			this->addClassButt->Text = L"Add Class";
			this->addClassButt->UseVisualStyleBackColor = true;
			this->addClassButt->Click += gcnew System::EventHandler(this, &UIForm::addClassButt_Click);
			// 
			// daysOfWeek
			// 
			this->daysOfWeek->FormattingEnabled = true;
			this->daysOfWeek->Items->AddRange(gcnew cli::array< System::Object^  >(8) { L"M", L"T", L"W", L"R", L"F", L"MW", L"TR", L"MWF" });
			this->daysOfWeek->Location = System::Drawing::Point(254, 60);
			this->daysOfWeek->Name = L"daysOfWeek";
			this->daysOfWeek->Size = System::Drawing::Size(111, 21);
			this->daysOfWeek->TabIndex = 22;
			this->daysOfWeek->Text = L"Days of the Week";
			// 
			// daysLabel
			// 
			this->daysLabel->AutoSize = true;
			this->daysLabel->Location = System::Drawing::Point(254, 45);
			this->daysLabel->Name = L"daysLabel";
			this->daysLabel->Size = System::Drawing::Size(93, 13);
			this->daysLabel->TabIndex = 23;
			this->daysLabel->Text = L"Days of the Week";
			// 
			// UIForm
			// 

			//TODO:
			//Find way to make screen full size
			//Add better overlap checking

			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(1360, 768);
			this->Controls->Add(this->daysLabel);
			this->Controls->Add(this->daysOfWeek);
			this->Controls->Add(this->addClassButt);
			this->Controls->Add(this->richTextBox);
			this->Controls->Add(this->instructorLabel);
			this->Controls->Add(this->roomLabel);
			this->Controls->Add(this->buildingLabel);
			this->Controls->Add(this->endLabel);
			this->Controls->Add(this->startLabel);
			this->Controls->Add(this->sectionLabel);
			this->Controls->Add(this->courseLabel);
			this->Controls->Add(this->departmentLabel);
			this->Controls->Add(this->instructorName);
			this->Controls->Add(this->roomNumber);
			this->Controls->Add(this->buildingName);
			this->Controls->Add(this->endTime);
			this->Controls->Add(this->startTime);
			this->Controls->Add(this->sectionNumber);
			this->Controls->Add(this->courseNumber);
			this->Controls->Add(this->departmentName);
			this->Controls->Add(this->FileButton);

			//adding all of my items
			//NW
			this->Controls->Add(this->listBox1);
			this->Controls->Add(this->classListLabel);
			this->Controls->Add(this->crossBox);
			this->Controls->Add(this->crossBoxLabel);
			this->Controls->Add(this->dualBox);
			this->Controls->Add(this->dualBoxLabel);
			this->Controls->Add(this->classBox);
			this->Controls->Add(this->modsLabel);
			this->Name = L"UIForm";
			this->Text = L"Class Scheduler";
			this->ResumeLayout(false);
			this->PerformLayout();
		};

	//The function for the dual taught box being clicked, changes the selected classes teamtaught boolean value
	//NW
	private: System::Void dualbox_Click(System::Object^ sender, System::EventArgs^ e){
				 if (classBox->Items->Count == 0){
					 MessageBox::Show("Please load a file first");
					 dualBox->Checked = false;
				 }
				 else{
					 classArray[classBox->SelectedIndex]->setTeamTaught();
				 }
	}

	 //the function for the crosslisted button being clicked, changes the selected classes crosslisted boolean value
	//NW
	private: System::Void crossListBox_Click(System::Object^ sender, System::EventArgs^ e){
				 if (classBox->Items->Count == 0){
					 MessageBox::Show("Please load a file first");
					 crossBox->Checked = false;
				 }
				 else{
					 classArray[classBox->SelectedIndex]->setCrossListed();
				 }
	}

	//The method that is called when a class is selected to change some of the modifications of it
	//NW
	private: System::Void classbox_Click(System::Object^ sender, System::EventArgs^ e){
				 if (classBox->SelectedIndex == 0){
					 MessageBox::Show("Please select a class, what you selected is not a class");
				 }
				 else if (classBox->SelectedIndex == 1){
					 MessageBox::Show("Please select a class, what you selected is not a class");
				 }
				 else if (classBox->Items->Count == 0){
					 MessageBox::Show("Please load a file first");
				 }
				 else{

					 if (classArray[classBox->SelectedIndex]->getCrossListed() == true){
						 crossBox->Checked = true;
					 }
					 else{
						 crossBox->Checked = false;
					 }
					 if (classArray[classBox->SelectedIndex]->getTeamTaught() == true){
						 dualBox->Checked = true;
					 }
					 else{
						 dualBox->Checked = false;
					 }
				 }
	}


	//The function that is called when two classes are selected to check if they overlap
	//NW
	private: System::Void listbox1_Click(System::Object^ sender, System::EventArgs^ e){
				 int count = 0;

				 for (int i = 0; i < listBox1->Items->Count; i++)
				 {
					 if (listBox1->GetSelected(i)){
						 count++;
						 if (count > 2){
							 MessageBox::Show("Only select up to two classes at a time!");
							 listBox1->ClearSelected();
						 }
						 else{

							 if (first == -1){
								 first = listBox1->SelectedIndices[0];
							 }
							 else if (second == -1){
								 second = listBox1->SelectedIndices[1];
							 }
							 else{
								 bool x = classArray[first]->Overlaps(classArray[second]);
								 richTextBox->SelectionColor = System::Drawing::Color::Red;
								 first = -1;
								 second = -1;
								 if (x){
									 richTextBox->SelectionAlignment = HorizontalAlignment::Center;
									 richTextBox->ForeColor = System::Drawing::Color::Red;
									 richTextBox->SelectionFont = gcnew System::Drawing::Font("Times New Roman", 30);
									 richTextBox->Text = "THE TWO CLASSES OVERLAP\n";
									 richTextBox->Text += "Try the following:";
									 listBox1->ClearSelected();
								 }
								 else{
									 richTextBox->ForeColor = System::Drawing::Color::Green;
									 richTextBox->SelectionAlignment = HorizontalAlignment::Center;
									 richTextBox->SelectionFont = gcnew System::Drawing::Font("Times New Roman", 30);
									 richTextBox->Text = "THE CLASSES DO NOT OVERLAP";
									 listBox1->ClearSelected();
								 }
							 }
						 }
					 }
				 }
	}

#pragma endregion





	//Used a few times for simplicity
	//NW
	private: std::string convertSTDString(System::String^ string){
				 //converts a managed string to a std::string
				 using System::IntPtr;
				 using System::Runtime::InteropServices::Marshal;

				 IntPtr intPointer = Marshal::StringToHGlobalAnsi(string);
				 std::string output = static_cast<const char*>(intPointer.ToPointer());
				 Marshal::FreeHGlobal(intPointer);
				 return output;
	}



	//The method that populates the classArray elements
	//NW
	private: void createClass(String^ s){
				 int freeArrayIndex = 0;
				 //converts String^ to std::string
				 string fileName = convertSTDString(s);

				 //converting std::string to system::string
				 String^ temp = gcnew String(fileName.c_str());

				 //begin file IO 
				 //the input file 
				 std::ifstream inputFile(fileName);
				 //the max array size = 256 
				 char oneline[256];
				 //the character to split the line at 
				 char delimit = ',';
				 string values[100];

				 //placeholders for the variables
				 string nameHolder;
				 int start = 0;
				 int end = 0;
				 string department;
				 string section;
				 string room;
				 string building;
				 int course = 0;
				 string days;

				 //the placeholder for the spot in the file you are at
				 int placeHolder = 0;
				 //the while loop for the entire file
				 while (inputFile){
					 /*
					 TODO
					 implement better way than if/else tree for choosing which portion to instantiate
					 */

					 inputFile.getline(oneline, 256, delimit);
					 string x = string(oneline);
					 //oneline works, file is read correctly
					 // String^ test = gcnew String(x.c_str());
					 // MessageBox::Show(test, "oneline");

					 if (placeHolder == 0){
						 nameHolder = oneline;
						 placeHolder++;

					 }
					 else if (placeHolder == 1){
						 start = atoi(oneline);
						 placeHolder++;
					 }
					 else if (placeHolder == 2){
						 end = atoi(oneline);
						 placeHolder++;
					 }
					 else if (placeHolder == 3){
						 department = oneline;
						 placeHolder++;
					 }
					 else if (placeHolder == 4){
						 section = oneline;
						 placeHolder++;
					 }
					 else if (placeHolder == 5){
						 room = oneline;
						 placeHolder++;
					 }
					 else if (placeHolder == 6){
						 building = oneline;
						 placeHolder++;
					 }
					 else if (placeHolder == 7){
						 course = atoi(oneline);
						 placeHolder++;
					 }
					 else if (placeHolder == 8){
						 days = oneline;
						 placeHolder++;
					 }
					 else{
						 //create class object, gets the next line, and sets the instructors name as well as resets the placeholder variable
						 classArray[freeArrayIndex] = new Class(nameHolder, start, end, department, section, room, building, course, days);
						 freeArrayIndex++;
						 nameHolder = oneline;
						 placeHolder = 1;
					 }
				 }
				 richTextBox->Clear();
				 printFullArray(freeArrayIndex);
	}

	//prints all of the elements in the classArray to each of the list boxes with appropriate information
	//NW
	private: void printFullArray(int maxItems){
				 for (int i = 0; i < maxItems; i++){
					 string x = classArray[i]->toString();
					 String^ convert = gcnew String(x.c_str());
					 string info = classArray[i]->toString();
					 String^ info2 = gcnew String(info.c_str());
					 listBox1->Items->Add(info2);

					 //getting selected information to put in class list box
					 int classNum = classArray[i]->getCourseNumber();
					 string section = classArray[i]->getSection();
					 string teacher = classArray[i]->getInstructor();
					 String^ section1 = gcnew String(section.c_str());
					 String^ teacher1 = gcnew String(teacher.c_str());
					 String^ allItems = "Course: " + classNum.ToString() + ", Section: " + section1 + ", Instructor: " + teacher1;
					 classBox->Items->Add(allItems);
				 }
	}

			 //Opens a selected file and displays it to the richTextBox by DAVID LADNIER
	private: Void FileButton_Click(System::Object^  sender, System::EventArgs^  e) {
				 System::Windows::Forms::DialogResult result = openFileDialog->ShowDialog();
				 //clears all list boxes when a new file is going to be selected
				 //NW
				 listBox1->Items->Clear();
				 classBox->Items->Clear();
				 classBox->Items->Add("Change classes being dual taught, or crosslisted");
				 classBox->Items->Add("----------------------------------------------------------------------------");
				 richTextBox->Clear();
				 //OK button was pressed. 
				 if (result == System::Windows::Forms::DialogResult::OK){
					 //MessageBox::Show(openFileDialog->FileName);
					 openFileName = openFileDialog->FileName;
					 try{
						 //Output the requested file in richTextBox.
						 createClass(openFileDialog->FileName);
						 //read all classes from the file, format them, and output them to the text box

						 fileOpened = true;
					 }
					 catch (...){

						 MessageBox::Show("So ya there is an error... this is embarrassing");
						 fileOpened = false;
					 }

					 Invalidate();
				 }
				 else{ //Cancel button was pressed.
					 if (result == System::Windows::Forms::DialogResult::Cancel)
					 {
						 return;
					 }
				 }



	}





			 //Appends the info selected in the comboboxes to the file that has been opened by DAVID LADNIER
	private: System::Void addClassButt_Click(System::Object^  sender, System::EventArgs^  e) {
				 String^ input;
				 try{

					 Object^ selectedDepartment = departmentName->SelectedItem;//1
					 Object^ selectedCourse = courseNumber->SelectedItem;//2
					 Object^ selectedSection = sectionNumber->SelectedItem;//3
					 Object^ selectedDays = daysOfWeek->SelectedItem;//3
					 Object^ selectedStart = startTime->SelectedItem;//4
					 Object^ selectedEnd = endTime->SelectedItem;//5
					 Object^ selectedBuilding = buildingName->SelectedItem;//6
					 Object^ selectedRoom = roomNumber->SelectedItem;//7
					 Object^ selectedInstructor = instructorName->SelectedItem;//8

					 MessageBox::Show("You have added:\n" + selectedDepartment->ToString() + " "
						 + selectedCourse->ToString() + "."
						 + selectedSection->ToString() + "\nOn: "
						 + selectedDays->ToString() + "\nStarting at: "
						 + selectedStart->ToString() + " Ending at: "
						 + selectedEnd->ToString() + "\nIn: "
						 + selectedBuilding->ToString() + " "
						 + selectedRoom->ToString() + "\nWith: "
						 + selectedInstructor->ToString() + "\n");

					 input = "\"" + selectedInstructor->ToString() + "\"," +
						 selectedStart->ToString() + "," + selectedEnd->ToString() + ","
						 + "\"" + selectedDepartment->ToString() + "\"," + selectedSection->ToString() + "," +
						 "\"" + selectedRoom->ToString() + "\"," + "\"" + selectedBuilding->ToString() + "\"," +
						 selectedCourse->ToString() + "," + "\"" + selectedDays->ToString() + "\n" + "\", ";


					 // This text is added only once to the file. 
					 if (File::Exists(openFileName)){

						 // Create a file to write to.
						 StreamWriter^ sw = File::AppendText(openFileName);
						 try{
							 sw->WriteLine(input);
						 }
						 finally{
							 if (sw){
								 delete (IDisposable^)sw;
							 }
						 }

					 }
					 else{
						 MessageBox::Show("You must Open a File");
						 FileButton_Click(sender, e);
						 return;
					 }

				 }
				 catch (...){
					 MessageBox::Show("You must fill all fields");
					 return;
				 }
				 //clearing the list box, and then creating the class objects
				 //NW
				 listBox1->Items->Clear();
				 createClass(openFileName);
	}


	};
}
